﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Model;
using Bll;
using System.Web.Services;

namespace 财会系.navigation
{
    public partial class navigation : System.Web.UI.Page
    {
        ModelPublic m = new ModelPublic();
        bllNavigation b = new bllNavigation();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                NavBind();
            }
        }

        public void NavBind()
        {
            RpNav.DataSource = b.Nav_Name_All();
            RpNav.DataBind();
        }

        private void ContentUpdate()
        {
            string message=b.Update_Information(m);
            if (message=="修改成功！")
            {
                Response.Write("<script>alert('"+message+"')</script>");                
            }
            else
            {
                Response.Write("<script>alert('"+message+"')</script>");                
            }
            NavBind();

        }

        protected void RpNav_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Label Id = (Label)e.Item.FindControl("lblId");
            Label Sort = (Label)e.Item.FindControl("lblSort");
            Label Name = (Label)e.Item.FindControl("lblName");
            Label Web = (Label)e.Item.FindControl("lblWebAdress");
            Label Show = (Label)e.Item.FindControl("lblShow");

            txtId.Text = Id.Text;
            
            txtName.Text = Name.Text.Trim();
            txtSort.Text = Sort.Text.Trim();
            txtWebAddress.Text = Web.Text.Trim();
            if (Show.Text == "True")
            {
                CboxShow.Checked = true;
            }
            else
                CboxShow.Checked = false;
        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            
            m.Name = "'"+txtName.Text + "'";
            m.Id = "'" + txtId.Text + "'";
            m.Sort = "'" + txtSort.Text + "'";
            if (txtWebAddress.Text == "")
                m.Web = "NULL";
            else
                m.Web = "'" + txtWebAddress.Text+"'";
            m.SqlId = "1";
            if (CboxShow.Checked == false)
                m.Show = "'False'";
            else
                m.Show = "'True'";

            ContentUpdate();            
        }

        protected void BtnRest_Click(object sender, EventArgs e)
        {
            Response.Redirect("../../admin/navigation/navigation.aspx");
        }
    }
}